<template>
  <div class="innerPageTable-box-OneTwo innerPageTable-out-flex">
     <!-- 搜索区域 -->
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="modelForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <Form-item prop="restUrl" :label="$t('module.tenantManage.restUrl')">
          <Input
            type="text"
            v-model.trim="searchForm.restUrl"
            placeholder
            
            @on-enter="search"
          ></Input>
        </Form-item>
        <Form-item prop="processInstanceId" :label="$t('module.tenantManage.processInstanceId')">
          <Input
            type="text"
            v-model.trim="searchForm.processInstanceId"
            placeholder
            
            @on-enter="search"
          ></Input>
        </Form-item>
        <Form-item prop="button" class="search-solt-btn">
           <RPButton optType="search" @click="search" />
           <RPButton optType="reset" @click="reset" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="modelListTable" :config="tableConfig" @page-change="pageChanged">
    </InnerPageTable>
    <Spin fix v-if="spinShow"></Spin>
  </div>
</template>

<script>
import { selectList, tryCallback } from '@api/flowable/tenantManage.js'
import { callbackColumns } from './columns.js'
import CallbackDetails from './callbackDetails.vue'
import IframeContainer from '@/components/IframeContainer.vue'
export default {
  name: 'callback-business',
  components: { IframeContainer },
  data() {
    return {
      spinShow: false,
      currentPageNum: 1,
      searchForm: {
        restUrl: '',
        processInstanceId: ''
      },
      tableConfig: {
        loadDataFn: ({ responseProcess, param }) => {
          selectList(param).then(({ data }) => {
            data.currentPage = data.pageNum
            delete data.pageNum
            data.recordCount = data.total
            delete data.total

            data.recordList = data.records
            delete data.records
            responseProcess(data)
          })
        },
        columnsFn: callbackColumns.bind(this),
        autoFirst: true
      }
    }
  },
  methods: {
    _launchProcess(row) {
      delete row.creater
      delete row.updater
      for (let i in row) {
        switch (i) {
          case 'restUrl':
            row[this.$t('module.tenantManage.requestUrl')] = row[i]
            delete row[i]
            break
          case 'reqBody':
            row[this.$t('module.tenantManage.reqBody')] = row[i]
            delete row[i]
            break
          case 'responseEntity':
            row[this.$t('module.tenantManage.responseEntity')] = row[i]
            delete row[i]
            break
          case 'resStatusCode':
            row[this.$t('module.tenantManage.resStatusCode')] = row[i]
            delete row[i]
            break
          case 'tryNum':
            row[this.$t('module.tenantManage.tryNum')] = row[i]
            delete row[i]
            break
          case 'processInstanceId':
            row[this.$t('module.tenantManage.processInstanceId')] = row[i]
            delete row[i]
            break
          case 'taskId':
            row[this.$t('module.tenantManage.taskId')] = row[i]
            delete row[i]
            break
          case 'errorMsg':
            row[this.$t('module.tenantManage.errorMsg')] = row[i]
            delete row[i]
            break
          case 'createTime':
            row[this.$t('module.tenantManage.createTime')] = row[i]
            delete row[i]
            break
          case 'updatTime':
            row[this.$t('module.tenantManage.updatTime')] = row[i]
            delete row[i]
            break
          case 'taskDefinitionKey':
            row[this.$t('module.tenantManage.taskDefinitionKey')] = row[i]
            delete row[i]
            break
        }
      }
      let resData = row
      new this.$pageModal(
        CallbackDetails,
        {
          props: {
            resData
          }
        },
        data => {
          if (data) {
            this.$refs['modelListTable'].load(this.searchForm, this.currentPageNum)
          }
        }
      )
    },
    _tryAgain(id) {
      this.spinShow = true
      tryCallback({ id: id })
        .then(res => {
          this.spinShow = false
          this.$Message.success({
            content: this.$t('module.tenantManage.tryAgainSuccess'),
            duration: 3
          })
          this.$refs['modelListTable'].load(this.searchForm, this.currentPageNum)
        })
        .catch(err => {
          this.spinShow = false
          this.$refs['modelListTable'].load(this.searchForm, this.currentPageNum)
        })
    },
    pageChanged(page) {
      this.currentPageNum = page
    },
    search() {
      //刷新列表
      this.$refs['modelListTable'].load(this.searchForm)
    },
    reset() {
      this.$refs['modelForm'].resetFields()
      this.search()
    }
  }
}
</script>